//index.js
//获取应用实例
var app = getApp(),
  a = app.requirejs("core"),
  b = app.requirejs('api/kjb');
Page({
  data: {
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    page: 1,
    kj_type: 1,
    show: false,
    loaded: false,
    list: [],
    route: "kanjia_index",
    menu: app.tabBar,
    menu_show: false,
    config: app.config,
  },
  //底部导航跳转
  menu_url: function (k) {
    a.menu_url(k, 2);
  },
  onLoad: function (e) {
    a.setting();
    if (e != null && e != undefined) {
      this.setData({
        tabbar_index: e.tabbar_index ? e.tabbar_index : -1
      });
    }
    this.setData({
      menu: getApp().tabBar
    })
    wx.setNavigationBarTitle({
      title: '砍价首页'
    })
    if (this.data.tabbar_index >= 0) {
      this.setData({
        showtabbar: getApp().tabBar.IsDiDis ? getApp().tabBar.IsDiDis : false,
      })
    }
    var that = this;
    var key = app.isInArray(getApp().tabBar.list, that.data.route);
    if (e.key && e.key == 1 && key) {
      that.setData({
        tabbar_index: key,
        showtabbar: getApp().tabBar.IsDiDis ? getApp().tabBar.IsDiDis : false,
      })
    }
    that.getList();
  
    b.BarIndex(function (i) {
      that.setData(i)
    })
  },
  getList: function () {
    var that = this,
      page = that.data.page,
      kj_type = that.data.kj_type,
      cate_id = '';
    b.kj_list(cate_id, kj_type, page, that, function (t) {
      console.log(t)
      that.setData(t)
    });
  },
  /**
   * 菜单转换
   */
  swichNav: function (e) {
    var that = this,
      k = a.pdata(e);
    k.list = [];
    k.page = 1;
    k.loaded = false;
    that.setData(k);
    this.getList();
  },
  /**
  * 下拉刷新
  */
  onPullDownRefresh: function () {
    this.setData({
      list: [],
      page: 1,
      loaded: false
    })
    this.getList()
    wx.stopPullDownRefresh();
  },
  /**
   *上拉加载
   */
  onReachBottom: function () {
    this.data.loaded || this.getList();
  },
  /**
   * 跳转至详情
   */
  url: function (e) {
    var data = a.pdata(e);
    if (data.goods_type == 2) {
      wx.navigateTo({
        url: '/yb_mingpian/pages/kanjia/goods_info/index?id=' + data.id
      })
    }
  }
})
